package com.aizhixin.lab.project.template.service;

import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.project.template.domain.ProjectSkillDomain;
import com.aizhixin.lab.project.template.entity.ProjectPost;
import com.aizhixin.lab.project.template.entity.ProjectSkill;
import com.aizhixin.lab.project.template.repository.ProjectSkillRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
@Transactional
public class ProjectSkillService {
    @Autowired
    private ProjectSkillRepository skillRepository;
    public Integer skillNum(String postId){
        return skillRepository.countByPostId(postId);
    }
    public List<ProjectSkill> findByPostIdIn(List<String> postIdList){
        return skillRepository.findByPostIdInAndDeleteFlag(postIdList,DataValidity.VALID.getState());
    }
    public ProjectSkill save(ProjectSkill domain) {

        return skillRepository.save(domain);
    }
    public List<ProjectSkill> save(List<ProjectSkill> domain) {

        return skillRepository.save(domain);
    }
    public List<ProjectSkill> findSkillList(String postId){
        return  skillRepository.findByPostIdAndDeleteFlag(postId, DataValidity.VALID.getState());
    }
    public List<ProjectSkillDomain> findSkillDomainList(String postId){
        List<ProjectSkill> projectSkillList = skillRepository.findByPostIdAndDeleteFlag(postId, DataValidity.VALID.getState());
        List<ProjectSkillDomain> projectSkillDomainList=new ArrayList<>();
        for (ProjectSkill projectSkill:projectSkillList){
            ProjectSkillDomain skillDomain = new ProjectSkillDomain();
            BeanUtils.copyProperties(projectSkill,skillDomain);
            projectSkillDomainList.add(skillDomain);
        }

        return projectSkillDomainList;
    }





}
